<?php

namespace app\common\model;

class MallUserAddress extends Base
{

    protected $deleteTime = "delete_time";

    /**
     * @param string $openid
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getUserAddressByList(string $openid = ''): array
    {
        return $this->field('id,realname,mobile,lng,lat,locatarea,address,isdefault,cityarea,areacode')
            ->where("openid",$openid)
            ->select()
            ->toArray();
    }

    /**
     * @param string $openid
     * @return MallUserAddress|array|mixed|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getUserAddressByDefaultInfo(string $openid = ""){
        return $this->where('openid',$openid)
            ->order('isdefault desc,id desc')
            ->find();
    }
}